package com.sixth.system.service.impl;/**
 * @author 633yh
 * @version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixth.core.entity.LoginInfo;
import com.sixth.core.entity.OperLog;
import com.sixth.core.vo.R;
import com.sixth.system.mapper.OperLogInfoMapper;
import com.sixth.system.service.OperLogInfoService;
import com.sixth.system.vo.LoginInfoVo;
import com.sixth.system.vo.OperLogInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;

/**
 * @author     ：Stu YH
 * @date       ：Created in 2024/8/20 17:10
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class OperLogInfoServiceImpl implements OperLogInfoService {
    @Autowired
    private OperLogInfoMapper operLogInfoMapper;
    @Override
    public R<IPage<OperLog>> selectByPage(OperLogInfoVo operLogInfoVo) {
        Page<OperLog> page = new Page<>(operLogInfoVo.getPageNum(), operLogInfoVo.getPageSize());
        QueryWrapper<OperLog> wrapper = new QueryWrapper<>();
        if (operLogInfoVo.getTitle()!=null){
            wrapper.like("title",operLogInfoVo.getTitle());
        }
        if (operLogInfoVo.getOperName()!=null){
            wrapper.like("oper_name",operLogInfoVo.getOperName());
        }
        if (operLogInfoVo.getOperatorType()!=null){
            wrapper.eq("operator_type",operLogInfoVo.getOperatorType());
        }
        if (operLogInfoVo.getRequestMethod()!=null){
            wrapper.eq("request_method",operLogInfoVo.getRequestMethod());
        }
        if (operLogInfoVo.getStatus()!=null){
            wrapper.eq("status",operLogInfoVo.getStatus());
        }
        if (StringUtils.hasText(operLogInfoVo.getBusinessType())){
            wrapper.eq("business_type",operLogInfoVo.getBusinessType());
        }
        if(operLogInfoVo.getDateRange()!=null&&operLogInfoVo.getDateRange().size()==2){
            wrapper.between("create_time",operLogInfoVo.getDateRange().get(0),operLogInfoVo.getDateRange().get(1));
        }
        Page<OperLog> operLogPage = operLogInfoMapper.selectPage(page, wrapper);
        return R.ok(operLogPage);

    }

    @Override
    public boolean deleteAll() {
        return operLogInfoMapper.deleteAll();
    }

    @Override
    public R removeByIds(Long[] ids) {
        operLogInfoMapper.deleteByIds(Arrays.asList(ids));
        return R.ok();
    }

    @Override
    public R save(OperLog operLog) {
        operLogInfoMapper.insert(operLog);
        return R.ok();
    }
}